//
//  PreViewController.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 15/11/21.
//  Copyright © 2015年 sgone. All rights reserved.
//

#import "PreViewController.h"
#import "UIImageView+AFNetworking.h"
#define imageHeight 200
@interface PreViewController ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation PreViewController


-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
        
    }
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
 
//    self.title = @"商品预览";
    self.titleLabel.text = @"商品预览";
    self.backBtn.hidden = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.view.backgroundColor = BACKGROUND1;
    self.tableView.backgroundColor = BACKGROUND1;


}



- (void)back:(UIButton *)sender {
    
    
//    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];

    
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;

}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return 3;


}




-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return 30;

}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    return imageHeight;

}


-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{

    return ViewHeight- imageHeight -60;

}



-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    
    
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 19, 19)];
    view1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view1];
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((ViewWidth-imageHeight)/2, 0, imageHeight, imageHeight)];
    [view1 addSubview:imageView];
    
    
    if ([[self.listDic objectForKey:@"image"] isKindOfClass:[NSNull class]] || [[self.listDic objectForKey:@"image"] length] == 0 ) {
        imageView.image = [UIImage imageNamed:@"backImage"];
    }

    NSURL *url = [ NSURL URLWithString:[self.listDic objectForKey:@"image"]];
    [imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"backImage"]];



    return view1;
}



-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{

    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
    view2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view2];
    //添加线条
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ViewWidth, 0.4)];
    view3.backgroundColor = [UIColor lightGrayColor];
    [view2 addSubview:view3];
    
    
    
    UILabel *lble = [[UILabel alloc]initWithFrame:CGRectMake(0, 1, 100,30)];
     lble.text = @"   商品描述";
     lble.textColor = [UIColor grayColor];
    lble.hidden = NO;
 
    [view2 addSubview:lble];
    
    
    //添加暂无描述
    
    UILabel *lbl2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 31, ViewWidth, 30)];
    lbl2.text = @"     暂无描述";
    [view2 addSubview:lbl2];
    lbl2.font = [UIFont systemFontOfSize:15];
    lbl2.textColor = [UIColor lightGrayColor];
    lbl2.hidden = YES;
    
    
    
    if ([[self.listDic objectForKey:@"description"]  length] == 0) {
        lbl2.hidden = NO;
        
    }
    
    else
    {
    
    lbl2.hidden = YES;
    UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 31, ViewWidth, ViewHeight-ViewWidth-60-1)];
    textView.editable = NO;
    textView.text = [NSString stringWithFormat:@"  %@",[self.listDic objectForKey:@"description"]];
   textView.textColor = [UIColor lightGrayColor];
    textView.font =[UIFont systemFontOfSize:15];
   [view2 addSubview:textView];
    
   }
    
    
    return view2;

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell3";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        

    }

    

    if (indexPath.row == 0) {
        cell.textLabel.text = [NSString stringWithFormat:@"%@",[self.listDic objectForKey:@"product_name"]];
        cell.textLabel.textColor = [UIColor grayColor];
    }
    else if (indexPath.row == 1)
    {
    
        cell.textLabel.textColor = [UIColor grayColor];
        cell.textLabel.text = [NSString stringWithFormat:@"规格 :%@",[self.listDic objectForKey:@"product_unit"]];
        cell.textLabel.font = [UIFont systemFontOfSize:15];
      
    
    }
    else
        
    {
    
        cell.textLabel.textColor = BenSe_COLOR;
        cell.textLabel.text = [NSString stringWithFormat:@"￥%@",[self.listDic objectForKey:@"unit_price"]];
    
    }
    
    
    return cell;


}





@end
